package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.GoodsBeen;
import cn.xfdzx.android.apps.shop.bean.SelectImageBeen;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;
import cn.xfdzx.android.apps.shop.contract.ItemLengthListener;

/**
 * @author gzk
 * @date 2020/4/13 0013
 * description：
 */
public class SelectImageAdapter extends RecyclerView.Adapter<SelectImageAdapter.MyViewHolder> {

    private ItemClickListener mItemClickListener;
    private List<SelectImageBeen.DataBean> mList;
    private Context mContext;
    private String type;
    private ItemLengthListener itemLengthListener;
    private ArrayList<String> imageUrl;


    public SelectImageAdapter(Context mContext, String type,ItemLengthListener lengthListener,ArrayList<String> imageUrl) {
        this.type = type;
        this.mContext = mContext;
        itemLengthListener=lengthListener;
        this.imageUrl=imageUrl;
    }

    public void setData(List<SelectImageBeen.DataBean> list) {
        this.mList = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_select_image, parent, false);
        MyViewHolder myHolder = new MyViewHolder(inflate);

        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {


        holder.tvGoodName.setText(mList.get(position).getName());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        holder.rvGoodImage.setLayoutManager(linearLayoutManager);
        SelectGoodsImageAdapter selectGoodsImageAdapter = new SelectGoodsImageAdapter(mContext, mList.get(position),type,position,itemLengthListener,imageUrl);

        holder.rvGoodImage.setAdapter(selectGoodsImageAdapter);
    }


    @Override
    public int getItemCount() {

        return null == mList ? 0 : mList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_good_name)
        TextView tvGoodName;
        @BindView(R.id.rv_good_image)
        RecyclerView rvGoodImage;


        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }


    public void setOnItemClickListener(ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;

    }

}
